package com.jhs.boot.schedule;

import com.jhs.boot.system.service.ScheduleTaskService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Classname ScheduleTask
 * @Description TODO
 * @Date 2025/8/14 11:23
 * @Created by zxy
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class ScheduleTask {
    private final ScheduleTaskService scheduleTaskService;
//    @Scheduled(cron = "${mesh.schedule.mpp}")
    @XxlJob("processMppJobHandler")
    public void processMpp() {
        log.info("  【心跳请求】 MPP {}", new Date());
        long start = System.currentTimeMillis();
        scheduleTaskService.heartMpp();
        long end = System.currentTimeMillis();
        log.info("  【心跳请求】 MPP结束，耗时：{} 毫秒 ", (end - start));
    }
//    @Scheduled(cron = "${mesh.schedule.map}")
    @XxlJob("processMapJobHandler")
    public void processMap() {
        log.info("  【心跳请求】 MAP {}", new Date());
        long start = System.currentTimeMillis();
        scheduleTaskService.heartMap();
        long end = System.currentTimeMillis();
        log.info("  【心跳请求】 MAP结束，耗时：{} 毫秒 ", (end - start));

    }
//    @Scheduled(cron = "${mesh.schedule.terminal}")
    @XxlJob("processClientJobHandler")
    public void processClient() {
        log.info("  【心跳请求】 终端 {}", new Date());
        long start = System.currentTimeMillis();
        scheduleTaskService.heartTerminal();
        long end = System.currentTimeMillis();
        log.info("  【心跳请求】 终端结束，耗时：{} 毫秒 ", (end - start));

    }

    /**
     * MMS主动请求节点上线
     */
    @XxlJob("processReqNodeUpJobHandler")
    public void processReqNodeUp() {
        log.info("  【MMS主动请求节点上线】   {}", new Date());
        long start = System.currentTimeMillis();
        scheduleTaskService.processReqNodeUp(null);
        long end = System.currentTimeMillis();
        log.info("  【MMS主动请求节点上线】  结束，耗时：{} 毫秒 ", (end - start));
    }
    @XxlJob("processDhcpJobHandler")
    public void processDhcp() {
        log.info("  【MMS主动请求DHCP】   {}", new Date());
        long start = System.currentTimeMillis();
        scheduleTaskService.processDhcp();
        long end = System.currentTimeMillis();
        log.info("  【MMS主动请求DHCP】  结束，耗时：{} 毫秒 ", (end - start));
    }
}
